﻿#region Usings

using System.Linq;
using System.Windows.Markup;
using SilverBox.Logging.Listeners;
using SilverBox.Logging.Providers;

#endregion

namespace SilverBox.Logging
{
    [ContentProperty("Providers")]
    public class Logger : ILogger<object>
    {
        public virtual ProviderCollection Providers { get; set; }

        public virtual ListenerCollection Listeners { get; set; }

        #region ILogger<object> Members

        public virtual void Log(object entry)
        {
            if (Check(entry))
            {
                var listeners = Listeners.Where(listener => listener.Condition(entry));

                foreach (var provider in Providers)
                {
                    foreach (var listener in listeners)
                    {
                        provider.Log(listener.GetString(entry));
                    }
                }
            }
        }

        #endregion

        public bool Check(object obj)
        {
            return Listeners.Any(listener => listener.Condition(obj));
        }
    }
}